<div class="page-toolbar">
    <div class="page-filter fl">
        <form class="layui-form layui-form-pane" action="{:url()}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
            <div class="layui-inline show">
                <label class="layui-form-label">父工厂</label>
                <div class="layui-input-inline xm-select-demo" id="demo2" style="width: auto;min-width: 250px;">
                </div>
            </div>
            <div class="layui-inline">
                <button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
            </div>
        </div>
        </form>
    </div>
</div>
{include file="mp@factory_v2/menu" /}
<table id="dataTable"></table>

{include file="system@block/layui" /}

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('edit')}?type_level=3&id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe" hisi-data="{width: '470px', height: '400px'}" title="修改工厂">修改</a>
	<a href="{:url('del')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>

<script type="text/html" title="排序模板" id="sortTpl">
    <input type="text" class="layui-input hisi-ajax-input input-sort" onkeyup="value=value.replace(/[^\d]/g,'')" value="{{ d.order }}" data-value="{{ d.id }}" data-href="{:url('sort')}?id={{ d.id }}&field=order">
</script>

<script type="text/html" id="toolbar">
    <div class="layui-btn-group fl">
        <a href="{:url('add?type_level=3')}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine hisi-iframe" hisi-data="{width: '470px', height: '500px'}" title="添加工厂">&nbsp;添加</a>
		<a data-href="{:url('status?val=0')}" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon layui-icon-close red">&nbsp;删除</a>
    </div>
</script>
<script type="text/html" id="name_childrensTpl">
    {{ showSelect_factory_id(d.childList_array, d.id) }}
</script>
<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script type="text/javascript">
    layui.use(['table'], function() {
        var table = layui.table;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                {type:'checkbox', fixed:'left'}
                ,{field: 'id', title: '编号', sort: true}
                ,{field: 'type', title: '工厂类型'}
                ,{field: 'name', title: '工厂名称'}
                ,{field: 'name_pids', title: '父工厂名称'}
                // ,{field: 'name_childrens', title: '子工厂集' , templet: '#name_childrensTpl'}
                ,{field: 'sort', title: '排序', templet: '#sortTpl'}
                ,{title: '操作', templet: '#buttonTpl', fixed: 'right'}
            ]]
        });
    });
    var menu_factory_json = {:json_encode($menu_factory)};

    var demo2 = xmSelect.render({
        el: '#demo2',
        name:'pids',
        autoRow: true,
        filterable: true,
        tree: {
            //是否显示树状结构
            show: true,
            //是否展示三角图标
            showFolderIcon: true,
            //是否显示虚线
            showLine: true,
            //间距
            indent: 20,
            //默认展开节点的数组, 为 true 时, 展开所有节点
            expandedKeys: [],
            //是否严格遵守父子模式
            strict: false,
            //是否开启极简模式
            simple: false,
            //点击节点是否展开
            clickExpand: true,
            //点击节点是否选中
            clickCheck: true
        },
        //是否严格遵守父子模式
        strict: false,
        toolbar: {
            show: true,
            list: ['ALL', 'REVERSE', 'CLEAR']
        },
        height: 'auto',
        data(){
            return menu_factory_json
        }
    })

    //工厂/分组下的 工厂设置
    function showSelect_factory_id(childList_array,id=0) {
        var html='<select name="factory_id" id="factory_id-'+id+'" class="mimo-select factory-id" data-key="'+id+'" lay-ignore="">' ;
        $.each( childList_array, function(i, n){
            var selected='';
            html+='<option value="'+n.id+'" '+selected+'>'+n.name+'</option>';
        });
        html+='</select>';
        return html;
    }
</script>